new Vue({
    el: '#follow',
    data: {
        users: null,
        articles: null,
        showIndex: 0
    },
    methods: {
    },
    created:function(){
        let that = this
        get("/getFollow", function(data){
            that.users = data
            if (data.length != 0) {
                getArticlesByUserId(that, data[0].userId)
            }
            // 左侧导航栏的切换以及数据请求
            $(function(){
                let items = $("#follow .leftNav li")
                items.each(function(index){
                    $(this).click(function(){
                        that.showIndex = index
                        getArticlesByUserId(that, data[index].userId)
                        items.each(function(){
                            $(this).removeClass("active")
                        })
                        $(this).addClass("active")
                    })
                })
            })   
        })
    }
})


function getArticlesByUserId(that, userId){
    get("/getArticlesByUserId/" + userId, function(data){
        that.articles = data
    })
}
